#include <bits/stdc++.h>
#define rep(a, b, c) for(a = b; a <= c; ++a)
#define ll long long
#define dis(v1, v2, a) (v2 + v1) * (v2 - v1) * 1.0 / (2 * a)
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 5;
void chmax(int &x, int y){x = max(x, y);}
void chmin(int &x, int y){x = min(x, y);}
int T, n, m, len, V, i, j, k;
int logn[N];
pair<int,int> st[N][20];
int b[3005]; //at which detector the i-th car starts(a[i] >= 0)
//              or finishes(a[i] < 0) being overspeed
int R, l, r;
double d[N], v[N], a[N], p[N],cnt[N];
set <int> s;

void init(){
    logn[1] = 0;
    rep(i, 2, m)logn[i] = logn[i / 2] + 1;
    rep(i, 1, m){
        st[i][0] = {cnt[i], i};
    }
    k = n;
    rep(i, 1, logn[n] + 1){
        rep(j, 1, n){
            if(st[j][i - 1].fi >= st[j + 1 << (i - 1)][i - 1].fi){
                int k1 = st[j << 1][i].fi, k2 = st[j << 1][i].se;
                st[j][i] = {k1, k2};
            }
            else{
                int k1 = st[j + 1 << (i - 1)][i - 1].fi, k2 = st[j + 1 << (i - 1)][i - 1].se;
                st[j][i] = {k1, k2};
            }
        }
    }
}

void solve1(){
    int cnt = 0;
    rep(i, 1, n){
        l = lower_bound(p + 1, p + n + 1,d[i]) - p;
        r = (a[i] < 0 ? (lower_bound(p + 1, p + 1 + n, dis(v[i], 0, a[i])) - p) : m);
        int sel;
        if(a[i] >= 0){
                b[i] = upper_bound(p + 1, p + 1 + n, dis(v[i], V, a[i])) - p;
                k = logn[r - b[i] + 1];
                if(st[b[i]][k].fi >= st[r - 1 << k + 1][k].fi){
                    sel = st[b[i]][k].se;
                }
                else{
                    sel = st[r - 1 << k + 1][k].se;
                }
        }
        else{
                b[i] = upper_bound(p + 1, p + 1 + n, dis(v[i], V, a[i])) - p - 1;
                k = logn[b[i] - l + 1];
                if(st[l][k].fi >= st[b[i] - 1 << k + 1][k].fi){
                    sel = st[l][k].se;
                }
                else{
                    sel = st[b[i] - 1 << k + 1][k].se;
                }
        }
        s.insert(sel);
        if(r <= b[i] && b[i] <= l)++cnt;
    }
    cout << cnt << '\n';
    cout << s.size() << '\n';
}

void solve2(){
    cout << "CSP rp++\n";
    cout << "I AK IOI\n";
}

void solve(){
    cin >> n >> m >> len >> V;
    rep(i, 1, n){
        cin >> d[i] >> v[i] >> a[i];
    }
    rep(i, 1, m){
        cin >> p[i];
    }
    #define N 1e8
    if(n > N || m > N){
        solve2();
    }
    else{
        solve1();
    }
}

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin.tie();
    cout.tie();
    ios::sync_with_stdio(0);
    cin >> T;
    while(--T)solve();
    return 0;
}
